package com.system.borrow.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.system.borrow.R;
import com.system.borrow.bean.LoanList;
import com.system.borrow.widget.FullyLinearLayoutManager;

import java.util.ArrayList;
import java.util.List;

/**
 * ================================================
 * 作    者：LuCenly(落尘)
 * 版    本：1.0
 * 创建日期：2016/12/8 18:58
 * 描    述：TODO
 * ================================================
 */
public class CardListAdapter extends BaseAdapter{
    private Context context;
    private LayoutInflater inflater;
    private List<LoanList> list = new ArrayList<>();

    public CardListAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public List<LoanList> getList() {
        return list;
    }

    public void setList(List<LoanList> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            convertView = inflater.inflate(R.layout.item_card_tuijian,null);
            viewHolder = new ViewHolder();
            viewHolder.iv_line = (ImageView) convertView.findViewById(R.id.iv_line);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.lv_data = (RecyclerView) convertView.findViewById(R.id.lv_data);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        LoanList tuiJian = list.get(position);
        viewHolder.tv_name.setText(tuiJian.name);
        if(position%2==0){
            viewHolder.iv_line.setImageResource(R.drawable.tz_line);
            viewHolder.tv_name.setTextColor(context.getResources().getColor(R.color.select_color));
        }else{
            viewHolder.iv_line.setImageResource(R.drawable.red_line);
            viewHolder.tv_name.setTextColor(context.getResources().getColor(R.color.red_line_color));
        }
        //设置布局管理器
        FullyLinearLayoutManager linearLayoutManager = new FullyLinearLayoutManager(context);
        viewHolder.lv_data.setLayoutManager(linearLayoutManager);
        //设置适配器
        CardList2Adapter mAdapter = new CardList2Adapter(context,tuiJian.dataList);
        viewHolder.lv_data.setAdapter(mAdapter);
        viewHolder.tv_name.setText(tuiJian.name);
        return convertView;
    }
    public class ViewHolder{
        ImageView iv_line;
        TextView tv_name;
        RecyclerView lv_data;
    }
}
